package com.itheima.a04myconvertstream;

import java.io.*;
import java.nio.charset.Charset;

public class ConvertStreamDemo2 {
    public static void main(String[] args) throws IOException {
        //将本地的GBK文件转为UTF-8

        //转换流（被淘汰的写法）
//        InputStreamReader isr = new InputStreamReader(new FileInputStream("myio\\hh.txt"),"GBK");
//        OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("myio\\hhh.txt"),"UTF-8");
//
//        int i;
//        while ((i=isr.read())!=-1){
//            osw.write(i);
//        }
//        osw.close();
//        isr.close();

        //jdk11以后的
        FileReader fr = new FileReader("myio\\hh.txt", Charset.forName("GBK"));
        FileWriter fw=new FileWriter("myio\\hhh.txt",Charset.forName("UTF-8"));
        int i;
        while ((i=fr.read())!=-1){
            fw.write(i);
        }
        fw.close();
        fr.close();

    }
}
